<?php
include($folder.'/layouts/code-behind/pickup.php');
function blc_pictures_select($from, $itemsPerPage)
{	
	switch ((int)$_GET['hivo'])
	{
		case 1:
			return query(
				'SELECT 
					p.id,
					p.name 
				FROM picture p
				WHERE
					NOT EXISTS (
						SELECT NULL
						FROM gallery_picture gp
						WHERE gp.gallery_id = :galleryId
							AND gp.picture_id = p.id
					)
				ORDER BY p.id 
				LIMIT :from,:itemsPerPage',
				array('galleryId'=>$_GET['galeria'], 'from'=>$from, 'itemsPerPage'=>$itemsPerPage));
			break;
		case 2:
			return query(
				'SELECT 
					p.id,
					p.name 
				FROM picture p
				WHERE
					NOT EXISTS (
						SELECT NULL
						FROM mainpicture mp
						WHERE mp.picture_id = p.id
					)
				ORDER BY p.id 
				LIMIT :from,:itemsPerPage',
				array('from'=>$from, 'itemsPerPage'=>$itemsPerPage));
			break;
	}
}
function blc_pictures_select_count()
{
	switch ((int)$_GET['hivo'])
	{
		case 1:
			return queryScalar('
				SELECT COUNT(p.id) 
				FROM picture p
				WHERE
					NOT EXISTS (
						SELECT NULL
						FROM gallery_picture gp
						WHERE gp.gallery_id = :galleryId
							AND p.id = gp.picture_id
					)', array('galleryId'=>$_GET['galeria']));
				break;
		case 2:
			return queryScalar('
				SELECT COUNT(p.id) 
				FROM picture p
				WHERE
					NOT EXISTS (
						SELECT NULL
						FROM mainpicture mp
						WHERE p.id = mp.picture_id
					)', null);
				break;
	}
}
?>